<?php
/**
 * 展示学生密码信息
 */
include "../util/DBUtil.php";
?>
<link rel="stylesheet" href="../css/bootstrap.min.css">
<div class="stuInfo">
    <table class="table table-striped">
        <tr>
            <th>ID</th>
            <th>学号</th>
            <th>姓名</th>
            <th>密码</th>
            <th>编辑</th>
        </tr>
        <?php
        $db = new DBUtil();
        $sql = "";
        $result = array();//存放结果集
        //关键字查询
        if ($_GET['action']=='key'){
            $key_type = $_POST['key_type'];
            $key = $_POST['key'];
            if ($key_type==0){//按学号查询
                $sql = "select * from tb_student where student_no like ? ";
                $params = array('%'.$key.'%');
                $result = $db->query($sql,$params);
            }elseif($key_type==1){//按姓名查询
                $sql = "select * from tb_student where name like ? ";
                $params = array('%'.$key.'%');
                $result = $db->query($sql,$params);
            }
        }else{  //显示所有
            $sql = "select * from tb_student";
            $result = $db->query($sql);
        }
        foreach ($result as $info){
            ?>
            <tr>
                <td><?php echo $info['id']?></td>
                <td><?php echo $info['student_no']?></td>
                <td><?php echo $info['name']?></td>
                <td><?php echo $info['password']?></td>
                <td>
                    <a href="../view/edit_pwd.php?id=<?php echo $info['id']?>" target="info">
                        <button class="btn btn-primary">修改</button>
                    </a>
                </td>
            </tr>
            <?
        }
        ?>
    </table>